home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14044 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++,
  4. Subject: Re: MS VC++ 4.0 namespace weirdness
  5. Date: 28 Mar 1996 22:54:56 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4jf5c0$dsr@news1.h1.usa.pipeline.com>
  8. References: <475745934wnr@ma.ccngroup.com>
  9. NNTP-Posting-Host: 38.8.120.15
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 28, 1996 10:06:33 in article <Re: MS VC++ 4.0 namespace weirdness>,
  16. 'Alan Griffiths <aGriffiths@ma.ccngroup.com>' wrote: 
  17.  
  18.  
  19. >In article: <4iq8up$hl3@news1.h1.usa.pipeline.com>   
  20. >grantp@usa.pipeline.com(Pete Grant) writes: 
  21. >>  
  22. >> [snip] 
  23. >> I have used namespace declarations inside header files, as in FOO1
  24. above,   
  25. >> and have had no problems.  The namespaces behave precisely as expected
  26. when 
  27. >> compiled with MSVC++4.0/4.1.   
  28. >Then your expectation is wrong... 
  29. >#include <assert.h> 
  30. >namespace MyNamespace 
  31. >{ 
  32. >int i = 1; 
  33. >} 
  34. >int main() 
  35. >{ 
  36. >int i = 2; 
  37. >using namespace MyNamespace; 
  38. >assert(2 == i);  // fails with MSVC4 
  39. >return 0; 
  40. >} 
  41.  
  42. If it's not too much trouble, could you cite the rule that makes 
  43. MSVC wrong in he above sample.  The way I read the draft, rule  
  44. 7.3.4 seems to apply in this case.  It says, in part,  
  45. "A using-directive specifies that the names in the namespace ... 
  46. can be used in the scope in which the using-directive appears 
  47. .. exactly as if the names from the namespace had been declared 
  48. outside the namespace at the points where the namespace was 
  49. defined. ..." 
  50.  
  51. Now, the last part of the sentence is confusing, but seems to 
  52. me that the name i is ambigous as it could be either unique::i 
  53. or MyNamespace::i.  Examples furnished in the draft appear to 
  54. confirm this.  Am I reading it wrong?  Or is it just the case 
  55. of local name vs. global? 
  56.  
  57. BTW, BC5 accepts the sample code using unique::i (the local one) 
  58. so you are probably correct as Borland historically has been 
  59. closer to the standard than Microsoft. 
  60.    
  61. -- 
  62. Pete Grant 
  63. Kalevi, Inc. 
  64. Software Engineering & development
  65.